#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct membership{
	char name[64];
    char password[64];
    char phone[64];
    long int money;
    char level[64];
    struct VIP *next;
}VIP;

VIP *top;
VIP *rear;

enum priceMode_item{
    retail,promotion,wholesale,gift
};
enum level_item{
    good,middle,bad
};

struct time_item{
    int year,month,day;
    int hour,minute,second;
};

typedef struct data_shelfItem {
    char name[64],type[64];
    double unitPrice;
    double kilo;
    struct time_item shelfTime;
    struct time_item life;
    enum priceMode_item priceMode;
    enum level_item level;
    struct data_shelfItem *next;
} fruitOnShelf;

void Grade_judge(VIP *p){
    int Lv;
    char VIP_grade[6][64]={"Lv.E","Lv.D","Lv.C","Lv.B","Lv.A","Lv.S"};
    Lv=p->money/2000;
    if(Lv<=2)
        strcpy(p->level,VIP_grade[0]);
    else if(Lv<=4)
        strcpy(p->level,VIP_grade[1]);
    else if(Lv<=6)
        strcpy(p->level,VIP_grade[2]);
    else if(Lv<=8)
        strcpy(p->level,VIP_grade[3]);
    else if(Lv<=10)
        strcpy(p->level,VIP_grade[4]);
    else 
        strcpy(p->level,VIP_grade[5]);
}

void saving(){
    VIP *user=top->next;
    FILE *fp=fopen("user.dat.txt","w");
    while(user!=NULL){
        fprintf(fp,"%s %s %s %ld %s",user->name,user->password,user->phone,user->money,user->level);
        user=user->next;
    }
    fclose(fp);
}

int phone_search(char phone[64]){
    VIP *p;
    p=top->next;
    while(p!=NULL){
        if(strcmp(phone,p->phone)==0)
            return 1;
        p=p->next;
    }
    return 0;
}

void sign_in(){
    int flag;
    char name[64];
    char password[64];
    char password_confirm[64];
    char phone[64];
    long int money;
    VIP *p=rear;
    printf("---->请输入您要添加的会员信息：\n");
    printf("---->请输入您的会员名：");
    scanf("%s",name);
    printf("---->请输入您的密码：\n");
    scanf("%s",password);
    printf("---->请确认您的密码：\n");
    scanf("%s",password_confirm);
    while(strcmp(password,password_confirm)!=0){
        system("cls");
        printf("---->您两次输入的密码不一致，请重新输入！\n");
        printf("---->请输入您的密码：\n");
        scanf("%s",password);
        printf("---->请确认您的密码：\n");
        scanf("%s",password_confirm);
    }
    printf("---->请输入您的电话号码：\n");
    scanf("%s",phone);
    flag=phone_search(phone);
    while(flag=1){
        system("cls");
        printf("---->该电话号码已被注册，请重新输入：\n");
        scanf("%s",phone);
        flag=phone_search(phone);
    }
}

int VIP_search(char name[64],char password[64]){
    VIP *p;
    p=top->next;
    while(p!=NULL){
        if(strcmp(name,p->name)==0&&strcmp(password,p->password)==0)
            return 1;
        p=p->next;
    }
    return 0;
}

int log_in1(){
    int temp;
    char username[64],userpassword[64];
    printf("-----会员登陆-----\n");
    printf("---->请输入您的会员名：\n");
    scanf("%s",username);
    printf("---->请输入您的密码：\n");
    scanf("%s",userpassword);
    temp=VIP_search(username,userpassword);
    return temp;
}

void log_in2(){
    int flag;
    flag=log_in1;
    while(flag==0){
        system("cls");
        printf("---->您输入的会员名或密码错误！\n");
        printf("---->请重新输入您的会员名和密码！\n");
        flag=log_in1();
    }
    if(flag==1){
        printf("---->登陆成功！\n");
        system("cls");
        user();
    }
}

void pay(){

}